﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zero.UControl.Base.Enums;

namespace Zero.UControl.Component
{
    public class MessageManage
    {
        public static Dictionary<string, MessageHost> MessageHosts { get; set; } = MessageHosts ?? new Dictionary<string, MessageHost>();

        public static void Default(string message, string token, int time = 3000)
        {
            Show(message, MessageType.Default, token, time);
        }

        public static void Success(string message, string token, int time = 3000)
        {
            Show(message, MessageType.Success, token, time);
        }

        public static void Warning(string message, string token, int time = 3000)
        {
            Show(message, MessageType.Warning, token, time);
        }

        public static void Error(string message, string token, int time = 3000)
        {
            Show(message, MessageType.Error, token, time);
        }

        private static void Show(string message, MessageType messageType, string token, double time)
        {
            if (!MessageHosts.ContainsKey(token)) return;
            var messageHost = MessageHosts[token];
            messageHost.Dispatcher.BeginInvoke((Action)(() =>
            {
                messageHost.Items.Add(new Message() { MessageType = messageType, Content = message, Time = (int)time, Uid = Guid.NewGuid().ToString() });
            }));
        }
    }
}
